package com.netty8018.httpserver;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @author liyanhao
 * @Date 2023-02-05 4:40
 */
public class TestServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        //向通道加入处理器
        //得到管道
        ChannelPipeline pipeline = ch.pipeline();
        //假如netty提供的httpServerCodec codc-->[code-decoder]
        // HttpServerCode说明
        // 1. htppServerCodec 是netty提供的处理http的编-解码器
        pipeline.addLast("MyHttpSeverCodec", new HttpServerCodec());
        //2 增加一个自定义的handler
        pipeline.addLast("MyTestHttpServerHandler", new TestHttpServerHandler());

    }
}
